<include file="Public/head"/>
<body class="no-skin">
<include file="Public/header"/>
<div class="main-container" id="main-container">
    <script type="text/javascript">
        try {
            ace.settings.check('main-container', 'fixed')
        } catch (e) {
        }
    </script>

    <include file="Public/sidebar"/>
    <div class="main-content">
        <div class="main-content-inner">
            <!-- #section:basics/content.breadcrumbs -->
            <include file="Public/breadcrumbs"/>

            <!-- /section:basics/content.breadcrumbs -->
            <div class="page-content">
                <include file="Public/set"/>

                <!-- /section:settings.box -->
                <div class="row">
                    <div class="col-xs-12">
                        <form class="form-horizontal" id="form" method="post" action="{$method}">
                            <!-- PAGE CONTENT BEGINS -->
                            <input type="hidden" name="id" value="{$vo.id}"/>
                            <input type="hidden" name="p" value="{$p}"/>
                            <input type="hidden" name="uid" value="{$vo.uid}"/>
                            <div class="form-group">
                                <label class="col-sm-1 control-label no-padding-right" for="form-field-0">
                                   平台分类 </label>
                                <div class="col-sm-9">
                                    <select id="cid" name="cid" class="col-xs-10 col-sm-5">
                                        <volist name="task_cate" id="tcate">
                                        <option value="{$tcate['id']}" <if condition="$tcate['id'] eq $vo['cid']">selected</if>>--{$tcate.title}--</option>
                                        </volist>
                                    </select>
                                    <span class="help-inline col-xs-12 col-sm-7">
												<span class="middle">选择所属平台分类。</span>
											</span>
                                </div>
                            </div>

                            <div class="space-4"></div>
                            
                            <if condition="$vo['id'] neq ''">
                            <div class="form-group">
                                <label class="col-sm-1 control-label no-padding-right" for="form-field-1">
                                    标题 </label>
                                <div class="col-sm-9">
                                    <input type="text" name="title" id="title" placeholder="任务标题"
                                           class="col-xs-10 col-sm-5" value="{$vo['title']}">
                                    <span class="help-inline col-xs-12 col-sm-7">
												<span class="middle">任务标题不能为空。</span>
											</span>
                                </div>
                            </div>
                            <div class="space-4"></div>
                            
                            <div class="form-group">
                                <label class="col-sm-1 control-label no-padding-right" for="form-field-1">
                                    任务地址 </label>
                                <div class="col-sm-9">
                                    <input type="text" name="url" id="url" placeholder="任务地址"
                                           class="col-xs-10 col-sm-5" value="{$vo['url']}">
                                    <span class="help-inline col-xs-12 col-sm-7">
												<span class="middle">任务地址必须填写。</span>
											</span>
                                </div>
                            </div>
                            <div class="space-4"></div>
                            
                            <else/>
                            <div class="form-group">
                                <label class="col-sm-1 control-label no-padding-right" for="form-field-1">
                                   任务信息</label>
                                <div class="col-sm-9">
                                	<input type="text" name="title[]" placeholder="任务标题" class="col-xs-10 col-sm-5">
                                    <input type="text" name="url[]" placeholder="任务地址" class="col-xs-10 col-sm-5" style="margin-left:6px;">
									<span>
										<a href="javascript:;" onclick="addInfo(this)" class="green" style="margin-left:5px;" title="增加"><i class="ace-icon fa fa-plus-circle bigger-100"></i></a>
									</span>
                                </div>
                            </div>
                           
                            <div class="space-4"></div>
                            <div id="data_info"></div>
                            </if>
                            <div class="form-group">
                                <label class="col-sm-1 control-label no-padding-right" for="form-field-1">
                                    任务要求 </label>
                                <div class="col-sm-9">
                                	 <volist name="money_type" id="money">	
                                	 <input id="money_type" class="money_type" name="money_type[]" value="{$money['id']}" 
                                	 data-id="{$money['id']}" data-price="{$money['price']}" 
                                	 <if condition="$money['checked'] eq 1">checked</if> type="checkbox"><label for="money_type">{$money.title}（￥{$money.price}）</label>
                                     </volist> 	
                                    
                                </div>
                            </div>
                            <div class="space-4"></div>
                            
                      <div class="form-group">
                                <label class="col-sm-1 control-label no-padding-right" for="form-field-1">
                                    价格 </label>
                                <div class="col-sm-9">
                                    <input type="number" readonly name="price" id="price" placeholder="任务价格"
                                           class="col-xs-10 col-sm-5" value="{$vo['price']}">
                                    
                                </div>
                            </div>
                            <div class="space-4"></div>      
                            
					<div class="form-group">
                                <label class="col-sm-1 control-label no-padding-right" for="form-field-1">
                                    任务数量 </label>
                                <div class="col-sm-9">
                                    <input type="number" name="num" id="num" placeholder="任务数量"
                                           class="col-xs-10 col-sm-5" value="{$vo['num']}">
                                    <span class="help-inline col-xs-12 col-sm-7">
												<span class="middle">任务数量必须填写。</span>
											</span>
                                </div>
                            </div>
                            <div class="space-4"></div>
                            <div class="form-group">
                                <label class="col-sm-1 control-label no-padding-right" for="form-field-1">
                                    总价 </label>
                                <div class="col-sm-9">
                                    <input type="number" readonly name="amount_price" id="amount_price" placeholder="总价"
                                           class="col-xs-10 col-sm-5" value="{$vo['amount_price']}">
                                </div>
                            </div>
                            <div class="space-4"></div>
                            
                            <div class="form-group">
                                <label class="col-sm-1 control-label no-padding-right" for="id-date-picker-1">截止日期</label>
                                <div class="col-xs-9 col-sm-9">
                                    <div class="input-group col-xs-5">
                                        <input class="form-control" id="end_t" name="end_t"
                                               value="{$vo['end_t']}" type="text"/>
                                        <span class="input-group-addon">
													<i class="ace-icon fa fa-calendar bigger-110"></i>
												</span>
												
                                    </div>
                                </div>
                            </div>
							<div class="space-4"></div>
							
							<div class="form-group">
                                <label class="col-sm-1 control-label no-padding-right" for="form-field-1">
                                    接单会员等级 </label>
                                <div class="col-sm-9">
                                	 <volist name="user_level" id="level">	
                                	 <input id="user_level" class="user_level" name="user_level" value="{$level['id']}" 
                                	 data-id="{$level['id']}" 
                                	 <if condition="$level['checked'] eq 1">checked</if> type="radio"><label for="user_level">{$level.title}</label>&nbsp;&nbsp;
                                     </volist> 	
                                    
                                </div>
                            </div>
                            <div class="space-4"></div>
                            
                            <div class="form-group">
                                <label class="col-sm-1 control-label no-padding-right" for="form-field-4">任务图片</label>
                                <div class="col-sm-9">
                                	<div class="col-xs-10 col-sm-5">{:BatchImage("pic",800,100,$vo['pic'])}</div>
                                </div>
                            </div>

                            <div class="space-4"></div>
                            
                            <div class="form-group">
                                <label class="col-sm-1 control-label no-padding-right" for="form-field-1">
                                    任务备注 </label>
                                <div class="col-sm-9">
                                <input type="text" name="remark" id="remark" placeholder="任务备注"
                                           class="col-xs-10 col-sm-5" value="{$vo['remark']}">
                                    <span class="help-inline col-xs-12 col-sm-7">
												<span class="middle"></span>
											</span>
								</div>			    
                            </div>
                            <div class="space-4"></div>
							<if condition="$vo.id neq ''">
                            <div class="form-group">
                                <label class="col-sm-1 control-label no-padding-right" for="form-field-2">
                                    支付状态： </label>
                                <div class="col-sm-9" style="padding-top: 6px;">
                                    <select id="pay_status" name="pay_status" class="col-xs-10 col-sm-5"> 
                                      <option value="0" <if condition="$vo.pay_status eq 0">selected</if>>待支付</option>
                                      <option value="1" <if condition="$vo.pay_status eq 1">selected</if>>已支付</option>
                                    </select>
                                </div>
                            </div>
                            <div class="space-4"></div>
                            </if>
                            <div class="col-md-offset-2 col-md-9">
                                <button class="btn btn-info submit" type="button">
                                    <i class="icon-ok bigger-110"></i>
                                    提交
                                </button>

                                &nbsp; &nbsp; &nbsp;
                                <button class="btn" type="button" onclick="history.back(-1);">
                                    <i class="icon-undo bigger-110"></i>
                                    取消
                                </button>
                            </div>

                            <!-- PAGE CONTENT ENDS -->


                        </form>
                    </div><!-- /.col -->
                </div><!-- /.row -->
            </div><!-- /.page-content -->
        </div>
    </div><!-- /.main-content -->
    <include file="Public/footer"/>

</div><!-- /.main-container -->

<include file="Public/footerjs"/>
<script type="text/javascript" src="__PUBLIC__/qwadmin/laydate/laydate.js"></script>
<!-- inline scripts related to this page -->
<script type="text/javascript">
	//时间选择器
	laydate.render({
	  elem: '#end_t'
	  ,type: 'date'
	  ,min: 0
	});
	
	function addInfo(obj){
		var _html = '<d><div class="form-group">';
		_html += '<label class="col-sm-1 control-label no-padding-right" for="form-field-1"></label>';
		_html += '<div class="col-sm-9">';
		_html += '<input type="text" name="title[]" placeholder="任务标题" class="col-xs-10 col-sm-5">';
		_html += '<input type="text" name="url[]" placeholder="任务地址" class="col-xs-10 col-sm-5" style="margin-left:6px;">';
		_html += '<span><a href="javascript:;" onclick="addInfo(this)" class="green" style="margin-left:5px;" title="增加"><i class="ace-icon fa fa-plus-circle bigger-100"></i></a>';
		_html += '<a href="javascript:;" onclick="delInfo(this)" class="red" style="margin-left:5px;" title="删除"><i class="ace-icon fa fa-minus-circle bigger-100"></i></a></span>';
		_html += '</div></div><div class="space-4"></div></d>';
		$("#data_info").append(_html);
	}

	function delInfo(obj){
		$_this = $(obj);
		$_this.parent().parent().parent().parent().remove();
	}
	
	//校验任务标题和任务地址是否存在空项
	function checkTitleInfo()
	{
		var r = 0;
		$("input[name='title[]']").each(function(){
			if($(this).val() == ''){
				r++;
			}
		});
		return r;
	}
	
	function checkUrlInfo()
	{
		var r = 0;
		$("input[name='url[]']").each(function(){
			if($(this).val() == ''){
				r++;
			}
		});
		return r;
	}
	
	
	function checkUrlMatch(){
		var r = 0;
		$("input[name='url[]']").each(function(){
			if(!checkURL($(this).val())){
				r++;
			}
		});
		return r;
	}
	
	function checkURL(URL){
		var str=URL;
		//判断URL地址的正则表达式为:http(s)?://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?
		//下面的代码中应用了转义字符"\"输出一个字符"/"
		var Expression=/http(s)?:\/\/([\w-]+\.)+[\w-]+(\/[\w- .\/?%&=]*)?/;
		var objExp=new RegExp(Expression);
		if(objExp.test(str)==true){
			return true;
		}else{
			return false;
		}
	} 

	
	
    $(function () {
        $("#tabs").tabs();
        $(".submit").click(function () {
        	var tr = checkTitleInfo();
        	var ur = checkUrlInfo();
        	var cr = checkUrlMatch();
            var cid = $("#cid").val(); 
            var price = $("#price").val();
            var num = $("#num").val();
            var title = $("#title").val();
            var url = $("#url").val();
            var amount_price = $("#amount_price").val();
            var id = "{$vo.id}";
            
            
            if (cid == '') {
                bootbox.dialog({
                    title: '友情提示：',
                    message: "平台分类必须选择。",
                    buttons: {
                        "success": {
                            "label": "确定",
                            "className": "btn-danger"
                        }
                    }
                });
                return;
            }
            if(id == ''){
            	if(tr>0 || ur >0){
                	bootbox.dialog({
                        title: '友情提示：',
                        message: "任务标题或任务地址存在空项。",
                        buttons: {
                            "success": {
                                "label": "确定",
                                "className": "btn-danger"
                            }
                        }
                    });
                    return;
                }
            	
            	if(cr > 0){
            		bootbox.dialog({
                        title: '友情提示：',
                        message: "任务地址必须以http(s)开头。",
                        buttons: {
                            "success": {
                                "label": "确定",
                                "className": "btn-danger"
                            }
                        }
                    });
                    return;
            	}
            }else{
            	if (title == '') {
                    bootbox.dialog({
                        title: '友情提示：',
                        message: "任务标题不能为空。",
                        buttons: {
                            "success": {
                                "label": "确定",
                                "className": "btn-danger"
                            }
                        }
                    });
                    return;
                }
            	
            	if (url == '') {
                    bootbox.dialog({
                        title: '友情提示：',
                        message: "任务地址不能为空。",
                        buttons: {
                            "success": {
                                "label": "确定",
                                "className": "btn-danger"
                            }
                        }
                    });
                    return;
                }
            	
            	if(!checkURL(url)){
            		bootbox.dialog({
                        title: '友情提示：',
                        message: "任务地址必须以http(s)开头。",
                        buttons: {
                            "success": {
                                "label": "确定",
                                "className": "btn-danger"
                            }
                        }
                    });
                    return;
            	}
            }
            
            if (!$(".money_type").is(':checked') || price == '' || price == 0) {
                bootbox.dialog({
                    title: '友情提示：',
                    message: "任务要求必须选择。",
                    buttons: {
                        "success": {
                            "label": "确定",
                            "className": "btn-danger"
                        }
                    }
                });
                return;
            }
            if (num == '' || amount_price == '') {
                bootbox.dialog({
                    title: '友情提示：',
                    message: "任务数量必须填写。",
                    buttons: {
                        "success": {
                            "label": "确定",
                            "className": "btn-danger"
                        }
                    }
                });
                return;
            }
            
            if (!$(".user_level").is(':checked')) {
                bootbox.dialog({
                    title: '友情提示：',
                    message: "接单会员等级必须选择。",
                    buttons: {
                        "success": {
                            "label": "确定",
                            "className": "btn-danger"
                        }
                    }
                });
                return;
            }
            $("#form").submit();
        });
        $(".money_type").click(function(){
        	var price = 0.0;
        	$(".money_type").each(function(){
        		if($(this).is(':checked')){
        			price += parseFloat($(this).attr('data-price'));
        		}
        	});
        	$("#price").val(price);
        	var n = parseInt($("#num").val());
        	$("#amount_price").val(n * price);
        });
        $("#num").keyup(function(){
        	var n = parseInt($(this).val());
        	var p = parseFloat($("#price").val());
        	$("#amount_price").val(n * p);
        });
    });
</script>
</body>
</html>
